/*     */ package btsm.bean;
/*     */ 
/*     */ import java.io.PrintStream;
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.ResultSetMetaData;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ 
/*     */ public class sqlwork
/*     */ {
/*  15 */   String scsql = "";
/*  16 */   String addsql = "";
/*  17 */   String mdsql = "";
/*  18 */   String delsql = "";
/*     */ 
/*  20 */   String strDQXSFilter = "5113%";
/*  21 */   public String tablesw = "";
/*  22 */   public String wheresw = "";
/*  23 */   public String idsw = "";
/*     */ 
/*  25 */   public String textsw = null;
/*  26 */   private dbConnector dbcon = null;
/*  27 */   private sysPro sPro = new sysPro();
/*     */ 
/*     */   public sqlwork(String tableswa, String idswa)
/*     */   {
/*  31 */     this.tablesw = tableswa;
/*  32 */     this.idsw = idswa;
/*  33 */     this.strDQXSFilter = this.sPro.getPFilter();
/*  34 */     dbConInit();
/*     */   }
/*     */ 
/*     */   private void dbConInit() {
/*  38 */     if (this.dbcon == null)
/*  39 */       this.dbcon = new dbConnector();
/*     */   }
/*     */ 
/*     */   public void dbConClose() {
/*  43 */     if (this.dbcon != null)
/*  44 */       this.dbcon.closeAll();
/*  45 */     this.dbcon = null;
/*     */   }
/*     */ 
/*     */   public ResultSet scmeta()
/*     */     throws Exception
/*     */   {
/*  52 */     dbConInit();
/*     */ 
/*  54 */     this.scsql = ("select * from " + this.tablesw + " limit 1");
/*  55 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/*  56 */     ResultSet rs = this.dbcon.execQuery(this.scsql);
/*  57 */     return rs;
/*     */   }
/*     */ 
/*     */   public String[] meta(ResultSet rs)
/*     */     throws Exception
/*     */   {
/*  63 */     dbConInit();
/*     */ 
/*  65 */     ResultSetMetaData rsmd = rs.getMetaData();
/*  66 */     int columnCount = rsmd.getColumnCount();
/*  67 */     String[] cols = new String[columnCount];
/*  68 */     for (int i = 0; i < columnCount; i++) {
/*  69 */       cols[i] = rsmd.getColumnLabel(i + 1);
/*     */     }
/*  71 */     return cols;
/*     */   }
/*     */ 
/*     */   public String[] metatype(ResultSet rs) throws Exception
/*     */   {
/*  76 */     dbConInit();
/*     */ 
/*  78 */     ResultSetMetaData rsmd = rs.getMetaData();
/*  79 */     int columnCount = rsmd.getColumnCount();
/*  80 */     String[] coltype = new String[columnCount];
/*  81 */     for (int i = 0; i < columnCount; i++) {
/*  82 */       coltype[i] = rsmd.getColumnTypeName(i + 1);
/*     */     }
/*  84 */     return coltype;
/*     */   }
/*     */ 
/*     */   public int getCountPage()
/*     */     throws Exception
/*     */   {
/*  91 */     dbConInit();
/*     */ 
/*  93 */     int count = 0;
/*  94 */     ResultSet rs = null;
/*     */ 
/*  96 */     this.scsql = ("select count(*) as count from " + this.tablesw);
/*     */     try
/*     */     {
/*  99 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 100 */       rs = this.dbcon.execQuery(this.scsql);
/* 101 */       if (rs.next())
/* 102 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 105 */       throw e;
/*     */     }
/*     */ 
/* 108 */     return count;
/*     */   }
/*     */ 
/*     */   public int getCableCountPage()
/*     */     throws Exception
/*     */   {
/* 114 */     dbConInit();
/*     */ 
/* 116 */     int count = 0;
/* 117 */     ResultSet rs = null;
/* 118 */     if (this.idsw.equalsIgnoreCase(""))
/* 119 */       this.scsql = ("select count(occode) as count from " + this.tablesw);
/*     */     else
/* 121 */       this.scsql = ("select count(id) as count from " + this.tablesw);
/*     */     try
/*     */     {
/* 124 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 125 */       rs = this.dbcon.execQuery(this.scsql);
/* 126 */       if (rs.next())
/* 127 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 130 */       throw e;
/*     */     }
/*     */ 
/* 133 */     return count;
/*     */   }
/*     */ 
/*     */   public int getUsersCountPage()
/*     */     throws Exception
/*     */   {
/* 139 */     dbConInit();
/*     */ 
/* 141 */     int count = 0;
/* 142 */     ResultSet rs = null;
/* 143 */     if (this.idsw.equalsIgnoreCase(""))
/* 144 */       this.scsql = ("select count(username) as count from " + this.tablesw);
/*     */     else
/* 146 */       this.scsql = ("select count(id) as count from " + this.tablesw);
/*     */     try
/*     */     {
/* 149 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 150 */       rs = this.dbcon.execQuery(this.scsql);
/* 151 */       if (rs.next())
/* 152 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 155 */       throw e;
/*     */     }
/*     */ 
/* 158 */     return count;
/*     */   }
/*     */ 
/*     */   public ResultSet scpage(int ShowPagesw, int PageSizesw)
/*     */     throws Exception
/*     */   {
/* 165 */     dbConInit();
/* 166 */     this.scsql = ("select * from " + this.tablesw + " order by id desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */ 
/* 168 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 169 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public ResultSet DicPage(int ShowPagesw, int PageSizesw)
/*     */     throws Exception
/*     */   {
/* 175 */     dbConInit();
/*     */ 
/* 177 */     this.scsql = ("select * from " + this.tablesw + " order by dictype, diccode desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/* 178 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/*     */ 
/* 180 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public ResultSet DicFPage(int ShowPagesw, int PageSizesw, String strdictype) throws Exception
/*     */   {
/* 185 */     dbConInit();
/*     */ 
/* 187 */     this.scsql = ("select * from " + this.tablesw + " where dictype = \"" + strdictype + "\" order by dictype, diccode desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/* 188 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 189 */     System.out.println("DicFPageSql: " + this.scsql);
/* 190 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public ResultSet interconBFPage(int ShowPagesw, int PageSizesw, String strFilter) throws Exception
/*     */   {
/* 195 */     dbConInit();
/*     */ 
/* 197 */     this.scsql = ("select * from " + this.tablesw + " where isname like \"%" + strFilter + "%\" or isurl like \"%" + strFilter + "%\" order by isname, isurl, id desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/* 198 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 199 */     System.out.println("interconBFPage: " + this.scsql);
/* 200 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public ResultSet scCablePage(int ShowPagesw, int PageSizesw)
/*     */     throws Exception
/*     */   {
/* 207 */     dbConInit();
/*     */ 
/* 209 */     if (this.idsw.equalsIgnoreCase(""))
/* 210 */       this.scsql = ("select * from " + this.tablesw + " order by occode desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     else {
/* 212 */       this.scsql = ("select * from " + this.tablesw + " order by id desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     }
/* 214 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 215 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public ResultSet scUsersPage(int ShowPagesw, int PageSizesw)
/*     */     throws Exception
/*     */   {
/* 221 */     dbConInit();
/*     */ 
/* 223 */     if (this.idsw.equalsIgnoreCase(""))
/* 224 */       this.scsql = ("select * from " + this.tablesw + " where username <> 'system' order by username desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     else {
/* 226 */       this.scsql = ("select * from " + this.tablesw + " where username <> 'system' order by id desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     }
/* 228 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 229 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public int getCountList(String dictype) throws Exception
/*     */   {
/* 234 */     dbConInit();
/*     */ 
/* 236 */     int count = 0;
/* 237 */     ResultSet rs = null;
/* 238 */     this.scsql = ("select count(dicname) from dictionary where dictype=\"" + dictype + '"');
/*     */     try {
/* 240 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 241 */       rs = this.dbcon.execQuery(this.scsql);
/* 242 */       if (rs.next())
/* 243 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 246 */       throw e;
/*     */     }
/*     */ 
/* 249 */     return count;
/*     */   }
/*     */ 
/*     */   public String[] sclist(String dictype) throws Exception
/*     */   {
/* 254 */     dbConInit();
/*     */ 
/* 256 */     String[] list = new String[getCountList(dictype)];
/* 257 */     int i = 0;
/* 258 */     this.scsql = ("select dicname from dictionary  where dictype=\"" + dictype + '"');
/* 259 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 260 */     ResultSet rs = this.dbcon.execQuery(this.scsql);
/* 261 */     while (rs.next()) {
/* 262 */       list[i] = rs.getString(1);
/* 263 */       i++;
/*     */     }
/* 265 */     return list;
/*     */   }
/*     */ 
/*     */   public int getCountdqxsList() throws Exception
/*     */   {
/* 270 */     dbConInit();
/*     */ 
/* 272 */     int count = 0;
/* 273 */     ResultSet rs = null;
/* 274 */     this.scsql = ("select count(distcode) from districtcode where distcode like \"" + this.strDQXSFilter + "\"");
/*     */     try {
/* 276 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 277 */       rs = this.dbcon.execQuery(this.scsql);
/* 278 */       if (rs.next())
/* 279 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 282 */       throw e;
/*     */     }
/*     */ 
/* 285 */     return count;
/*     */   }
/*     */ 
/*     */   public String[] scdqxslist() throws Exception
/*     */   {
/* 290 */     dbConInit();
/*     */ 
/* 292 */     String[] list = new String[getCountdqxsList()];
/* 293 */     int i = 0;
/*     */ 
/* 295 */     this.scsql = ("select district from districtcode where distcode like \"" + this.strDQXSFilter + "\" order by distcode;");
/* 296 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 297 */     ResultSet rs = this.dbcon.execQuery(this.scsql);
/* 298 */     while (rs.next()) {
/* 299 */       list[i] = rs.getString(1);
/* 300 */       i++;
/*     */     }
/*     */ 
/* 303 */     return list;
/*     */   }
/*     */ 
/*     */   public ResultSet sc()
/*     */     throws Exception
/*     */   {
/* 309 */     dbConInit();
/*     */ 
/* 311 */     if (this.wheresw.equalsIgnoreCase(""))
/*     */     {
/* 313 */       this.scsql = ("select * from " + this.tablesw);
/* 314 */     } else if (this.idsw.equalsIgnoreCase(""))
/* 315 */       this.scsql = ("select * from " + this.tablesw + " where btscode=" + '"' + this.wheresw + '"');
/*     */     else {
/* 317 */       this.scsql = ("select * from " + this.tablesw + " where id=" + '"' + this.wheresw + '"');
/*     */     }
/* 319 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/*     */ 
/* 321 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public boolean add(String[] para)
/*     */   {
/* 328 */     dbConInit();
/*     */ 
/* 330 */     boolean flag = true;
/* 331 */     if (this.idsw.equalsIgnoreCase(""))
/* 332 */       this.addsql = ("insert into " + this.tablesw + " values(");
/*     */     else {
/* 334 */       this.addsql = ("insert into \"" + this.tablesw + '"' + " values(0,");
/*     */     }
/* 336 */     for (int i = 0; i < para.length - 1; i++) {
/* 337 */       if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null")))
/* 338 */         this.addsql += "\"\",";
/*     */       else
/* 340 */         this.addsql = (this.addsql + '"' + para[i] + '"' + ",");
/*     */     }
/* 342 */     if ((para[(para.length - 1)].equalsIgnoreCase("")) || (para[(para.length - 1)].equals("null")))
/* 343 */       this.addsql += "\"\")";
/*     */     else
/* 345 */       this.addsql = (this.addsql + '"' + para[(para.length - 1)] + '"' + ")");
/*     */     try
/*     */     {
/* 348 */       this.addsql = new String(this.addsql.getBytes("ISO8859-1"), "UTF-8");
/* 349 */       System.out.println(this.addsql);
/* 350 */       this.dbcon.execUpdate(this.addsql);
/*     */     } catch (Exception ex) {
/* 352 */       flag = false;
/* 353 */       ex.printStackTrace();
/*     */     }
/* 355 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean md(String[] para)
/*     */   {
/* 361 */     dbConInit();
/*     */ 
/* 363 */     boolean flag = true;
/* 364 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/* 365 */     String strCurDate = sdf.format(new Date());
/*     */ 
/* 367 */     String[] metaa = new String[para.length];
/*     */     try {
/* 369 */       metaa = meta(scmeta());
/*     */     } catch (Exception ex) {
/* 371 */       flag = false;
/* 372 */       ex.printStackTrace();
/*     */     }
/*     */ 
/* 375 */     if (this.idsw.equalsIgnoreCase("")) {
/* 376 */       this.mdsql = ("update " + this.tablesw + " set ");
/* 377 */       for (int i = 0; i < para.length; i++) {
/* 378 */         if (i < para.length - 1) {
/* 379 */           if (metaa[i].equalsIgnoreCase("refreshtime"))
/* 380 */             this.mdsql = (this.mdsql + metaa[i] + "=\"" + strCurDate + "\",");
/* 381 */           else if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null")))
/* 382 */             this.mdsql = (this.mdsql + metaa[i] + "=\"\", ");
/*     */           else {
/* 384 */             this.mdsql = (this.mdsql + metaa[i] + "=" + '"' + para[i] + '"' + ',');
/*     */           }
/*     */         }
/* 387 */         else if (metaa[i].equalsIgnoreCase("refreshtime"))
/* 388 */           this.mdsql = (this.mdsql + metaa[i] + "=\"" + strCurDate + "\" ");
/* 389 */         else if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null")))
/* 390 */           this.mdsql = (this.mdsql + metaa[i] + "=\"\" ");
/*     */         else {
/* 392 */           this.mdsql = (this.mdsql + metaa[i] + "=" + '"' + para[i] + '"' + ' ');
/*     */         }
/*     */       }
/*     */ 
/* 396 */       this.mdsql = (this.mdsql + " where btscode=" + '"' + this.wheresw + '"');
/*     */     } else {
/* 398 */       this.mdsql = ("update " + this.tablesw + " set ");
/* 399 */       for (int i = 1; i < para.length; i++) {
/* 400 */         if (i < para.length - 1) {
/* 401 */           if (metaa[i].equalsIgnoreCase("refreshtime"))
/* 402 */             this.mdsql = (this.mdsql + metaa[i] + "=\"" + strCurDate + "\",");
/* 403 */           else if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null")))
/* 404 */             this.mdsql = (this.mdsql + metaa[i] + "=\"\", ");
/*     */           else {
/* 406 */             this.mdsql = (this.mdsql + metaa[i] + "=" + '"' + para[i] + '"' + ',');
/*     */           }
/*     */         }
/* 409 */         else if (metaa[i].equalsIgnoreCase("refreshtime"))
/* 410 */           this.mdsql = (this.mdsql + metaa[i] + "=\"" + strCurDate + "\" ");
/* 411 */         else if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null")))
/* 412 */           this.mdsql = (this.mdsql + metaa[i] + "=\"\" ");
/*     */         else {
/* 414 */           this.mdsql = (this.mdsql + metaa[i] + "=" + '"' + para[i] + '"' + ' ');
/*     */         }
/*     */       }
/*     */ 
/* 418 */       this.mdsql = (this.mdsql + " where id=" + '"' + this.wheresw + '"');
/*     */     }
/*     */     try {
/* 421 */       this.mdsql = new String(this.mdsql.getBytes("ISO8859-1"), "UTF-8");
/* 422 */       this.dbcon.execUpdate(this.mdsql);
/*     */     } catch (Exception ex) {
/* 424 */       flag = false;
/* 425 */       ex.printStackTrace();
/*     */     }
/* 427 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean del()
/*     */   {
/* 434 */     dbConInit();
/*     */ 
/* 436 */     boolean flag = true;
/* 437 */     if (this.idsw.equalsIgnoreCase(""))
/* 438 */       this.delsql = ("delete from " + this.tablesw + " where btscode=" + '"' + this.wheresw + '"');
/*     */     else
/* 440 */       this.delsql = ("delete from " + this.tablesw + " where id=" + '"' + this.wheresw + '"');
/*     */     try
/*     */     {
/* 443 */       this.delsql = new String(this.delsql.getBytes("ISO8859-1"), "UTF-8");
/* 444 */       this.dbcon.execUpdate(this.delsql);
/*     */     } catch (Exception ex) {
/* 446 */       flag = false;
/* 447 */       ex.printStackTrace();
/*     */     }
/* 449 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean DisableTr() {
/* 453 */     boolean flag = true;
/*     */     try {
/* 455 */       this.dbcon.trgDisable();
/*     */     } catch (Exception ex) {
/* 457 */       flag = false;
/* 458 */       ex.printStackTrace();
/*     */     }
/* 460 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean AbleTr()
/*     */   {
/* 465 */     dbConInit();
/*     */ 
/* 467 */     boolean flag = true;
/*     */     try {
/* 469 */       this.dbcon.trgEnable();
/*     */     }
/*     */     catch (Exception ex)
/*     */     {
/* 473 */       flag = false;
/* 474 */       ex.printStackTrace();
/*     */     }
/* 476 */     return flag;
/*     */   }
/*     */ 
/*     */   public ResultSet excelve(String ve)
/*     */     throws Exception
/*     */   {
/* 482 */     dbConInit();
/*     */ 
/* 484 */     this.scsql = ("select * from " + ve);
/* 485 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 486 */     ResultSet rs = this.dbcon.execQuery(this.scsql);
/* 487 */     return rs;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     btsm.bean.sqlwork
 * JD-Core Version:    0.6.2
 */